<template>
	<view>
		<loadstatusVue :status="data.loadStatus">
			<view class="contents">
				<view class="right_item" v-for="(item, index) in data.list" :key="index" @click="$pageGo(`/pages/activity/info?id=${item.id}`)">
					<view class="right_item_block">
						<view class="">
							<image :src="item.imgFace" mode="aspectFill" :lazy-load="true"></image>
						</view>
						<view class="right_cont">
							<view class="">
								<view class="title">{{ item.name }}</view>
								<view class="tip flex">
									<view class="t1">{{ item.type }}</view>
									<view class="t2" v-if="item.sign == '1'">签到</view>
									<view class="t2">{{ item.lineType == 1 ? '线上' : '线下' }}</view>
								</view>
							</view>
							<view class="">
								<view class="user flex">
									<image v-if="item.createUser.img" :src="item.createUser.img" mode="aspectFill"></image>
									<image v-else src="https://www.daolangtongge.com/read-book-api/profile/mini_app/img/head.png" mode=""></image>
									<view class="">{{ item.createUser.name }}</view>
								</view>
								<view class="tips flex">
									<image src="/static/a1.png" mode=""></image>
									<view class="">{{ $formatDateTime(item.beginTime) }}</view>
								</view>
								<view class="tips flex" v-if="item.lineType == 1">
									<image src="/static/a3.png" mode=""></image>
									<view class="">{{ item.platform }}</view>
								</view>
								<view class="tips flex" v-else>
									<image src="/static/a2.png" mode=""></image>
									<view class="ts">{{ item.addressInfo }}</view>
								</view>
							</view>
						</view>

						<view v-if="item.verifyStatus == '已通过'" class="zt" :class="`zt-${$formatStatus(item.hotVerifyStatus)}`">
							<view class="" v-if="item.hotVerifyStatus == '待审核'">待平台审核</view>
							<view class="" v-if="item.hotVerifyStatus == '已通过'">推荐活动</view>
							<view class="" v-if="item.hotVerifyStatus == '已驳回'">推荐驳回</view>
						</view>
						<view v-else class="zt" :class="`zt-${$formatStatus(item.verifyStatus)}`">
							{{ item.verifyStatus }}
						</view>
					</view>
					<view class="tss" v-if="item.verifyStatus == '已驳回'">驳回原因：{{ item.verifyDesc }}</view>
					<view class="tss" v-if="item.hotVerifyStatus == '已驳回'">平台驳回原因：{{ item.hotVerifyDesc }}</view>
					<view class="bottom flex_jc_sb" @click.stop="">
						<view v-if="!getUserStatus(item).isEnded && getUserStatus(item).isApproved" :id="`text-flex-${index}`" class="text_flex" @click="toggleMenu(item, index)">
							更多
							<buttonGroupVue :show="btnData.showMenuIndex === index" :options="btnData.menuOptions" :trigger="btnData.triggerRect" @select="handleMenuSelect" />
						</view>
						<view class="" v-else></view>
						<view class="flex" v-if="item.verifyStatus == '待审核'">
							<view class="btn" @click="popupReviewOpen(item)">审核</view>
						</view>
						<view class="flex" v-if="item.verifyStatus == '已通过' && item.hotVerifyStatus != '待审核' && item.end === '0' && item.hot === '0'">
							<view class="btn" @click="popupApplyOpen(item)">申请推荐</view>
						</view>
					</view>
				</view>
			</view>
		</loadstatusVue>
		<view class="right_icon">
			<view class="icon flex_jc_cent" @click="open(1)">
				<uni-icons type="search" size="28" color="#75613E"></uni-icons>
			</view>
			<view v-show="data.list.length != 0" class="icon flex_jc_cent" @click="open(2)">
				<uni-icons type="download" size="28" color="#75613E"></uni-icons>
			</view>
		</view>
		<!-- 活动推荐到热门 -->
		<uni-popup ref="popupApply" type="center">
			<view class="globalPopup">
				<uni-icons @click="close" type="closeempty" size="20" class="close" color="#AEAEAE"></uni-icons>
				<view class="title">活动推荐到热门</view>
				<view class="shenhe" style="margin-top: 30rpx">
					<view class="popup_textarea">
						<textarea v-model="shenqingObj.hotApplyDesc" placeholder="请输入推荐原因" placeholder-class="input_text" maxlength="180" confirm-type="done"></textarea>
					</view>
				</view>
				<view class="btns flex_jc_sb">
					<view class="bt b1" @click="close">取消</view>
					<view class="bt b2" @click="handleSHENQING">确认</view>
				</view>
			</view>
		</uni-popup>
		<!-- 搜索弹窗 -->
		<uni-popup ref="popupSearch" type="center">
			<view class="globalPopup">
				<uni-icons @click="close" type="closeempty" size="20" class="close" color="#AEAEAE"></uni-icons>
				<view class="title">
					{{ isSearch == 1 ? '搜索活动' : '导出活动' }}
				</view>
				<view class="content_s">
					<view class="content_item flex">
						<view class="i_l">搜索</view>
						<view class="i_r">
							<input v-model="data.queryParams.name" type="text" placeholder="请输入活动名称" />
						</view>
					</view>
					<view class="content_item flex">
						<view class="i_l">筛选</view>
						<view class="i_r popup-date-picker">
							<uni-datetime-picker
								v-model="data.time"
								@change="timechange"
								:lefticon="false"
								:clear-icon="false"
								:border="false"
								type="daterange"
								rangeSeparator="至"
							/>
						</view>
					</view>

					<view class="content_item flex">
						<view class="i_l">状态</view>
						<view class="i_r" style="background: transparent">
							<scroll-view scroll-x class="i_r_scroll">
								<view
									class="items"
									v-for="(item, index) in btnData.typeList"
									:key="index"
									@click="changeType(item)"
									:class="item.value == data.queryParams.status ? 'actitems' : ''"
								>
									{{ item.name }}
								</view>
							</scroll-view>
						</view>
					</view>
				</view>
				<view class="btns flex_jc_sb" v-if="isSearch == 1">
					<view class="bt b1" @click="reset">重置</view>
					<view class="bt b2" @click="handleSearch">搜索</view>
				</view>
				<view class="btns flex_jc_sb" v-else>
					<view class="bt b1" @click="reset">重置</view>
					<view class="bt b2" @click="handleSearch(1)">导出xlsx</view>
					<view class="bt b2" @click="handleSearch(2)">导出活动</view>
				</view>
			</view>
		</uni-popup>
		<!-- 修改地址 -->
		<uni-popup ref="popupAddress" type="center">
			<view class="globalPopup">
				<uni-icons @click="close" type="closeempty" size="20" class="close" color="#AEAEAE"></uni-icons>
				<view class="title">修改地址</view>
				<view class="subtitle">原定地址：{{ btnData.btnItem?.addressInfo }}</view>
				<view class="block_1">
					<view class="tit">地图导航</view>
					<view class="input_flex flex" @click="selectDW">
						<view class="input" v-if="addressObj.address">
							{{ addressObj.address }}
						</view>
						<view class="flex input" v-else>
							<uni-icons type="location-filled" size="24" color="#75613E"></uni-icons>
							<view class="t1">请选择</view>
						</view>
					</view>
				</view>
				<view class="block_1" style="margin-bottom: 30rpx">
					<view class="tit">现场地址</view>
					<view class="input">
						<textarea v-model="addressObj.addressInfo" placeholder-class="input_class" type="text" placeholder="请输入" maxlength="30" />
					</view>
				</view>

				<view class="btns flex_jc_sb">
					<view class="bt b1" @click="close">取消</view>
					<view class="bt b2" @click="confirmEditAddress">确认</view>
				</view>
			</view>
		</uni-popup>
		<!-- 导出弹窗 -->
		<uni-popup ref="popupDown" type="center">
			<view class="globalPopup">
				<uni-icons @click="close" type="closeempty" size="20" class="close" color="#AEAEAE"></uni-icons>
				<view class="title">确认导出</view>
				<view class="content">是否确认导出活动？</view>
				<view class="btns flex_jc_sb">
					<view class="bt b1" @click="close">取消</view>
					<view class="bt b2" @click="downloadFile">确认</view>
				</view>
			</view>
		</uni-popup>
		<!-- 延迟时间弹窗 -->
		<uni-popup ref="popupTime" type="center">
			<view class="globalPopup">
				<uni-icons @click="close" type="closeempty" size="20" class="close" color="#AEAEAE"></uni-icons>
				<view class="title">延迟时间</view>
				<view class="time_s" v-if="btnData.btnItem?.beginTime">
					<view class="t1">原定时间：{{ $formatDateTime(btnData.btnItem.beginTime) }}</view>
					<view class="">
						<uni-datetime-picker :start="Date.now()" v-model="timeObj.beginTime" type="datetime" :hide-second="true" />
					</view>
				</view>
				<view class="btns flex_jc_sb">
					<view class="bt b1" @click="close">取消</view>
					<view class="bt b2" @click="handleRTime">确认</view>
				</view>
			</view>
		</uni-popup>
		<!-- 审核弹窗 -->
		<uni-popup ref="popupReview" type="center">
			<view class="globalPopup">
				<uni-icons @click="close" type="closeempty" size="20" class="close" color="#AEAEAE"></uni-icons>
				<view class="title">活动审核</view>
				<view class="shenhe">
					<view class="tit_right">
						<radio-group @change="radioChange">
							<label class="radio" style="color: #000">
								<radio style="transform: scale(0.7)" color="#B19561" value="已通过" />
								通过
							</label>
							<label class="radio" style="color: #000; margin-left: 50rpx">
								<radio style="transform: scale(0.7)" color="#B19561" value="已驳回" />
								驳回
							</label>
						</radio-group>
					</view>
					<view class="popup_textarea" v-if="shenheObj.verifyStatus == '已驳回'">
						<textarea v-model="shenheObj.verifyDesc" placeholder="请输入说明" placeholder-class="input_text" maxlength="180" confirm-type="done"></textarea>
					</view>
				</view>
				<view class="btns flex_jc_sb">
					<view class="bt b1" @click="close">取消</view>
					<view class="bt b2" @click="handleSHENHE">确认</view>
				</view>
			</view>
		</uni-popup>
		<!-- 更新群码 -->
		<uni-popup ref="popupImg" type="center">
			<view class="globalPopup">
				<uni-icons @click="close()" type="closeempty" size="20" class="close" color="#AEAEAE"></uni-icons>
				<view class="title">更新群码</view>
				<view class="upload">
					<image :src="btnData.btnItem.imgQr" mode="aspectFill"></image>
					<view class="ads" @click="chooseFENGMIAN(1)">重新上传</view>
				</view>
			</view>
		</uni-popup>
		<!-- 上传合影 -->
		<uni-popup ref="popupPhoto" type="center">
			<view class="globalPopup">
				<uni-icons @click="close()" type="closeempty" size="20" class="close" color="#AEAEAE"></uni-icons>
				<view class="title">上传合影</view>
				<view class="upload1" v-if="btnData.btnItem.endImg">
					<image :src="btnData.btnItem.endImg" mode="aspectFill"></image>
					<view class="adsts">重新上传</view>
				</view>
				<view class="upload1 flex_jc_cent" v-else>
					<image src="https://www.daolangtongge.com/read-book-api/profile/mini_app/img/upbcg.png" mode=""></image>
					<view class="ads flex_jc_cent" @click="chooseFENGMIAN(2)">
						<view class="">
							<image src="/static/bxj.png" mode=""></image>
							<view class="" style="margin-top: 10rpx">上传活动照片</view>
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script setup>
import { ref, reactive, getCurrentInstance, nextTick, onMounted, defineEmits, computed } from 'vue';
import { onPageScroll } from '@dcloudio/uni-app';
import buttonGroupVue from '@/components/buttonGroup/buttonGroup.vue';
import loadstatusVue from '@/components/loadstatus/loadstatus.vue';
import {
	getGroupActivityList,
	groupVerify,
	groupDelayTime,
	groupUpdateImgQr,
	groupUpdateEndImg,
	activityExport,
	groupApplyHot,
	activityExportText,
	activityUpdateAddress
} from '@/api/branch/factivity.js';
import { toast, showConfirm, showLoad, hideLoad } from '@/utils/common.js';
import fileDownloader from '@/utils/fileDownloader';
import { chooseAndUploadImage } from '@/utils/upload';
const instance = getCurrentInstance();
const { proxy } = getCurrentInstance();
const btnData = reactive({
	showMenuIndex: -1, // 初始化为-1，避免默认显示
	scrollTop: 0,
	triggerRect: {},
	btnItem: {
		id: '',
		beginTime: ''
	},
	menuOptions: [
		// 根据实际需求填写菜单选项
		{ label: '延迟时间', value: 'delay_time', isshow: false }, // 唯一值：延迟时间
		{ label: '更新群码', value: 'update_group_code', isshow: false }, // 唯一值：更新群码
		{ label: '报名成员', value: 'enrolled_members', isshow: false }, // 唯一值：报名成员
		{ label: '上传合影', value: 'upload_photo', isshow: false }, // 唯一值：上传合影
		{ label: '复制活动', value: 'export_activity', isshow: false },
		{ label: '修改地址', value: 'edit_address', isshow: false }
	],
	typeList: [
		{
			name: '全部',
			value: 0
		},
		{
			name: '待审核',
			value: 1
		},
		{
			name: '已通过',
			value: 2
		},
		{
			name: '已驳回',
			value: 3
		},
		{
			name: '待平台审核',
			value: 4
		},
		{
			name: '推荐已通过',
			value: 5
		},
		{
			name: '推荐已驳回',
			value: 6
		}
	]
});

const data = reactive({
	list: [],
	total: 0,
	loadStatus: 'before', // 加载状态
	hasMore: true, // 是否有更多数据
	isLoading: false, // 防止重复请求的锁
	queryParams: {
		pageNum: 1,
		pageSize: 10,
		name: '',
		beginTimeBegin: undefined,
		beginTimeEnd: undefined,
		status: 0
	},
	time: []
});

const getUserStatus = (item) => {
	return {
		isApproved: item.verifyStatus === '已通过', // 已审核通过
		isEnded: item.end === '1' // 已结束
	};
};
const props = defineProps({
	userId: 0
});
const changeType = (item) => {
	data.queryParams.status = item.value;
};
const isSearch = ref(1);
const open = (e) => {
	isSearch.value = e;
	popupSearch.value.open();
};
const timechange = (e) => {
	data.queryParams.beginTimeBegin = e[0];
	data.queryParams.beginTimeEnd = e[1];
};
const handleSearch = (type) => {
	if (isSearch.value == 1) {
		data.queryParams.pageNum = 1;
		getList();
		close();
	} else {
		if (!data.queryParams.beginTimeBegin) {
			toast('请先选择日期');
			return;
		}
		if (type == 1) {
			downloadFile();
		}
		if (type == 2) {
			showLoad('数据导出中...');
			activityExportText(data.queryParams).then((res) => {
				if (res.code == 200) {
					uni.setClipboardData({
						data: generateMultipleCopyText(res.data),
						success: function () {
							hideLoad();
							toast('活动内容已复制');
							close();
						},
						fail: function (err) {
							console.error('复制失败:', err);
							hideLoad();
						}
					});
				}
			});
		}
	}
};
// 生成多条数据的复制文本
const generateMultipleCopyText = (dataList) => {
	// 1. 按日期分组
	const groupedData = {};

	dataList.forEach((item) => {
		const dateKey = proxy.$formatTime(item.beginTime, 'month-day');
		if (!groupedData[dateKey]) {
			groupedData[dateKey] = [];
		}
		groupedData[dateKey].push(item);
	});

	// 2. 生成复制文本
	let copyText = '';

	Object.keys(groupedData).forEach((dateKey) => {
		const items = groupedData[dateKey];
		const weekStr = proxy.$formatTime(items[0].beginTime, 'week-day');

		// 日期标题
		copyText += `${dateKey}（${weekStr}）\n`;

		// 该日期下的所有活动
		items.forEach((item, index) => {
			const lineTypeText = item.lineType === '1' ? '线上' : '线下';
			const prefix = item.lineType === '1' ? '腾讯会议' : extractDistrict(item.addressInfo) || item.city;

			copyText += `${prefix}｜${lineTypeText}｜${item.name}｜${item.type}`;

			// 如果不是最后一条，添加换行
			if (index < items.length - 1) {
				copyText += '\n';
			}
		});

		copyText += '\n\n';
	});

	return copyText.trim();
};

// 提取区信息
const extractDistrict = (fullAddress) => {
	if (!fullAddress) return '';

	// 匹配：市 + 区/县 的模式
	const regex = /市([^市]+?(?:区|县|自治县))/;
	const match = fullAddress.match(regex);

	return match ? match[1] : '';
};
const reset = () => {
	data.queryParams.pageNum = 1;
	data.queryParams.name = '';
	data.time = [];
	data.queryParams.beginTimeBegin = undefined;
	data.queryParams.beginTimeEnd = undefined;
	data.queryParams.status = 0;
};
const downloadFile = async () => {
	close();
	try {
		await fileDownloader.downloadAndPreview({
			url: 'https://www.daolangtongge.com/read-book-api/mini/activity/group/export',
			data: data.queryParams,
			fileName: '活动信息.xlsx',
			fileType: 'xlsx'
		});
	} catch (error) {
		console.error('导出失败:', error);
	}
};

// 导出活动
onPageScroll((e) => {
	handleScroll(e.scrollTop);
});
const handleScroll = (scrollTop) => {
	// 快速滚动时立即关闭菜单
	if (btnData.showMenuIndex !== -1 && Math.abs(scrollTop - btnData.scrollTop) < 50) {
		btnData.showMenuIndex = -1;
	}
	btnData.scrollTop = scrollTop;
};
const isTimeExceeded = (targetTime) => {
	// 处理目标时间
	let targetTimestamp;

	if (targetTime instanceof Date) {
		targetTimestamp = targetTime.getTime();
	} else if (typeof targetTime === 'string') {
		const iosSafeDateStr = targetTime.replace(' ', 'T');
		targetTimestamp = new Date(iosSafeDateStr).getTime();
	} else if (typeof targetTime === 'number') {
		targetTimestamp = targetTime;
	} else {
		return false;
	}

	if (isNaN(targetTimestamp)) {
		return false;
	}

	const now = Date.now();
	return now > targetTimestamp;
};
// 重构的toggleMenu方法
const toggleMenu = async (item, index) => {
	Object.assign(btnData.btnItem, item);
	btnData.menuOptions[0].isshow = !isTimeExceeded(item.beginTime) && item.verifyStatus == '已通过';
	btnData.menuOptions[1].isshow = !isTimeExceeded(item.beginTime) && item.verifyStatus == '已通过';
	btnData.menuOptions[2].isshow = item.verifyStatus == '已通过';
	btnData.menuOptions[3].isshow = isTimeExceeded(item.beginTime) && item.verifyStatus == '已通过';
	btnData.menuOptions[4].isshow = item.verifyStatus == '已通过';
	btnData.menuOptions[5].isshow = item.lineType == '2' && !isTimeExceeded(item.beginTime) && item.verifyStatus == '已通过';
	// 快速切换时先关闭
	if (btnData.showMenuIndex === index) {
		btnData.showMenuIndex = -1;
		return;
	}
	// 使用轻量级位置计算
	try {
		const position = await calculateMenuPosition(index);
		btnData.triggerRect = position;
		btnData.showMenuIndex = index;
	} catch (error) {
		btnData.showMenuIndex = -1;
	}
};
// 高效的位置计算
const calculateMenuPosition = (index) => {
	return new Promise((resolve) => {
		// 使用IntersectionObserver获取位置信息
		const observer = uni.createIntersectionObserver(instance);
		observer.relativeToViewport();
		observer.observe(`#text-flex-${index}`, (res) => {
			if (res.intersectionRatio > 0) {
				resolve({
					top: res.boundingClientRect.top + res.boundingClientRect.height,
					left: res.boundingClientRect.left,
					height: res.boundingClientRect.height
				});
			} else {
				resolve({
					top: 0,
					left: 0,
					height: 0
				});
			}
			observer.disconnect();
		});
	});
};
const emit = defineEmits(['update:value']);
// 延迟函数
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
// 设置加载状态的方法
const setLoadStatus = (status, options = {}) => {
	data.loadStatus = status;
};
// 处理响应数据的通用方法
const handleResponseData = async (res, isLoadMore = false) => {
	// 如果是加载更多，确保loading状态至少显示500ms，避免闪烁
	if (isLoadMore) {
		await delay(500);
	}
	if (res.code == 200) {
		emit('update:value', res.total);
		// 处理数据
		if (isLoadMore) {
			data.list.push(...res.rows);
		} else {
			data.list = res.rows || [];
		}
		// 判断是否有更多数据
		data.hasMore = res.rows && res.rows.length >= data.queryParams.pageSize;
		// 设置状态
		if (data.list.length === 0) {
			setLoadStatus('empty');
		} else if (!data.hasMore) {
			setLoadStatus('noMore');
		} else {
			setLoadStatus('success');
		}
		return true;
	}
	return false;
};
// 获取列表数据
const getList = async (isLoadMore = false) => {
	// 防止重复请求
	if (data.isLoading) return;
	try {
		data.isLoading = true;
		if (isLoadMore) {
			if (!data.hasMore) return;
			setLoadStatus('loading');
		} else {
			setLoadStatus('before');
			// 初始加载时显示loading至少1秒，避免闪烁
			await delay(300);
		}
		const res = await getGroupActivityList(data.queryParams);
		const success = await handleResponseData(res, isLoadMore);
		if (!success) {
			// 请求失败的处理
			setLoadStatus(data.list.length === 0 ? 'empty' : 'success');
		}
	} catch (err) {
		await delay(300);
		setLoadStatus(data.list.length === 0 ? 'empty' : 'success');
	} finally {
		data.isLoading = false;
	}
};
// 加载更多方法 - 供父组件调用
const loadMore = () => {
	if (data.isLoading || !data.hasMore) {
		return false;
	}

	data.queryParams.pageNum++;
	getList(true); // 传递 true 表示是加载更多

	return true;
};
defineExpose({
	handleScroll,
	loadMore
});

onMounted(() => {
	getList();
});
// 菜单选择处理函数
const handleMenuSelect = (value) => {
	// 根据不同value处理逻辑
	switch (value) {
		case 'delay_time':
			console.log('处理延迟时间逻辑');
			// 调用延迟时间相关方法
			popupTime.value.open();
			break;
		case 'update_group_code':
			console.log('处理更新群码逻辑');
			// 调用更新群码相关方法
			popupImg.value.open();
			break;
		case 'enrolled_members':
			console.log('处理报名成员逻辑');
			// 调用查看报名成员相关方法
			uni.navigateTo({
				url: `/mypage/usertabbar/registration?id=${btnData.btnItem.id}&isshow=${!isTimeExceeded(btnData.btnItem.beginTime)}`
			});
			break;
		case 'upload_photo':
			console.log('处理上传合影逻辑');
			// 调用上传合影相关方法
			popupPhoto.value.open();
			break;
		case 'export_activity':
			const textToCopy =
				'星期：' +
				proxy.$formatTime(btnData.btnItem.beginTime, 'week-day') +
				'\n' +
				'日期：' +
				proxy.$formatTime(btnData.btnItem.beginTime, 'month-day') +
				'\n' +
				'活动地点所在区县：' +
				btnData.btnItem.addressInfo +
				'\n' +
				'活动类型：' +
				btnData.btnItem.type +
				'\n' +
				'活动名称：' +
				btnData.btnItem.name;
			uni.setClipboardData({
				data: textToCopy,
				success: function () {
					toast('活动内容已复制');
				},
				fail: function (err) {
					console.error('复制失败:', err);
				}
			});
			// 星期 日期 活动地点所在区县 活动类型 活动名称
			break;
		case 'edit_address':
			popupAddress.value.open();
			break;
		default:
			break;
	}
};
const popupSearch = ref(null);
const popupDown = ref(null);
const popupTime = ref(null);
const popupReview = ref(null);
const popupApply = ref(null);
const popupImg = ref(null);
const popupPhoto = ref(null);
const popupAddress = ref(null);
const close = () => {
	popupSearch.value.close();
	popupDown.value.close();
	popupTime.value.close();
	popupReview.value.close();
	popupImg.value.close();
	popupPhoto.value.close();
	popupApply.value.close();
	popupAddress.value.close();
};

const timeObj = reactive({
	id: '',
	beginTime: null
});
const handleRTime = () => {
	timeObj.id = btnData.btnItem.id;
	if (timeObj.beginTime == '') {
		toast('请选择时间');
		return;
	}
	groupDelayTime(timeObj).then((res) => {
		if (res.code == 200) {
			refresh('已延迟活动时间');
		}
	});
};

const popupReviewOpen = (item) => {
	btnData.btnItem = item;
	popupReview.value.open();
};
const popupApplyOpen = (item) => {
	btnData.btnItem = item;
	popupApply.value.open();
};
const shenqingObj = reactive({
	id: 0,
	hotApplyDesc: ''
});
// 推荐申请
const handleSHENQING = () => {
	if (shenqingObj.hotApplyDesc === '') {
		toast('请输入推荐原因');
		return;
	}
	shenqingObj.id = btnData.btnItem.id;
	groupApplyHot(shenqingObj).then((res) => {
		if (res.code === 200) {
			refresh('已申请');
		}
	});
};
const shenheObj = reactive({
	id: 0,
	verifyStatus: '',
	verifyDesc: ''
});
const radioChange = (e) => {
	shenheObj.verifyStatus = e.detail.value;
};
// 社长
const handleSHENHE = () => {
	if (shenheObj.verifyStatus === '') {
		toast('请选择审核结果');
		return;
	}
	if (shenheObj.verifyStatus === '已驳回' && shenheObj.verifyDesc === '') {
		toast('请输入驳回原因');
		return;
	}
	shenheObj.id = btnData.btnItem.id;
	groupVerify(shenheObj).then((res) => {
		if (res.code === 200) {
			refresh('已审核');
		}
	});
};
// 更新群吗
const chooseFENGMIAN = async (e) => {
	try {
		if (e == 1) {
			let imgurl = await chooseAndUploadImage({
				count: 1,
				uploadText: '上传中...'
			});
			if (imgurl) {
				groupUpdateImgQr({
					id: btnData.btnItem.id,
					imgQr: imgurl
				}).then((res) => {
					if (res.code == 200) {
						refresh('已更换群码');
					}
				});
			}
		}
		if (e == 2) {
			let imgurl = await chooseAndUploadImage({
				count: 1,
				uploadText: '上传中...'
			});
			if (imgurl) {
				groupUpdateEndImg({
					id: btnData.btnItem.id,
					endImg: imgurl
				}).then((res) => {
					if (res.code == 200) {
						refresh('已上传合影');
					}
				});
			}
		}
	} catch (err) {
		console.error('头像上传失败：', err);
	}
};

const addressObj = reactive({
	id: 0,
	address: '',
	addressInfo: '',
	longitude: '',
	latitude: ''
});
const selectDW = () => {
	uni.chooseLocation({
		latitude: btnData.btnItem.latitude,
		longitude: btnData.btnItem.longitude,
		success: function (res) {
			addressObj.address = res.name;
			addressObj.addressInfo = res.address;
			addressObj.longitude = res.longitude;
			addressObj.latitude = res.latitude;
		}
	});
};
// 修改地址
const confirmEditAddress = () => {
	addressObj.id = btnData.btnItem.id;
	if (addressObj.addressInfo == '' || addressObj.address == '') {
		toast('请选择地址');
		return;
	}
	activityUpdateAddress(addressObj).then((res) => {
		if (res.code == 200) {
			refresh('活动地址已修改');
		}
	});
};
const refresh = (tt) => {
	toast(tt);
	close();
	setTimeout(() => {
		getList();
	}, 500);
};
</script>

<style lang="scss" scoped>
.right_icon {
	position: fixed;
	z-index: 9;
	right: 20rpx;
	bottom: 160rpx;
	padding-bottom: constant(safe-area-inset-bottom);
	padding-bottom: env(safe-area-inset-bottom);
	.icon {
		width: 100rpx;
		height: 100rpx;
		background: #d8c6a7;
		border-radius: 50rpx;
		border: 1px solid #75613e;
		margin-top: 20rpx;
	}
}
.input_class {
	color: #d1d1d6;
	font-size: 28rpx;
	font-weight: 400;
}
.globalPopup {
	.subtitle {
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #8f8f8b;
		margin-top: 30rpx;
	}
	.block_1 {
		margin-top: 18rpx;
		.tit {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #8f8f8b;
		}
		.input {
			margin-top: 18rpx;
			width: 545rpx;
			border-radius: 12rpx;
			border: 1px solid #dadada;
			padding: 20rpx 24rpx;
			box-sizing: border-box;
			textarea {
				width: 100%;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #1b1b1b;
				height: 100rpx;
				line-height: 1.5;
				box-sizing: border-box;
			}
		}
	}
	.content_s {
		.content_item {
			height: 56rpx;
			margin: 30rpx auto;
			.i_l {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #75613e;
				margin-right: 20rpx;
			}

			.i_r {
				flex: 1;
				height: 56rpx;
				background: #eeeeee;
				border-radius: 12rpx 12rpx 12rpx 12rpx;
				input {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #000;
					height: 56rpx;
					line-height: 56rpx;
					padding-left: 18rpx;
				}
			}
			.i_r_scroll {
				width: 460rpx;
				display: flex;
				align-items: center; // 垂直居中选项
				white-space: nowrap;
				.items {
					display: inline-block;
					height: 56rpx;
					background: #eeeeee;
					border-radius: 12rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #8f8f8b;
					line-height: 56rpx;
					margin-right: 20rpx;
					text-align: center;
					padding: 0rpx 20rpx;
				}
				.actitems {
					background: #eae7dd;
					color: #75613e;
				}
			}
		}
	}
	.time_s {
		margin: 30rpx auto;
		.t1 {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #8f8f8b;
			margin-bottom: 20rpx;
		}
	}
	.shenhe {
		.tit_right {
			margin: 40rpx auto;
			font-size: 28rpx;
		}
		textarea {
			width: 100%;
			height: 160rpx;
			border: 1px solid #e5e5e5;
			border-radius: 4px;
			font-family: PingFang SC, PingFang SC;
			font-size: 28rpx;
			color: #000;
			padding: 10rpx;
			box-sizing: border-box;
			margin: 0rpx auto 30rpx;
		}
	}
	.upload {
		width: 400rpx;
		height: 400rpx;
		background: #f7f7f7;
		border-radius: 20rpx;
		border: 1px solid #dadada;
		margin: 50rpx auto;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #75613e;
		text-align: center;
		position: relative;
		image {
			width: 400rpx;
			height: 400rpx;
			border-radius: 20rpx;
		}
		.ads {
			position: absolute;
			width: 400rpx;
			height: 80rpx;
			background: rgba(0, 0, 0, 0.5);
			border-radius: 0rpx 0rpx 20rpx 20rpx;
			bottom: 0%;
			line-height: 80rpx;
			color: #ffffff;
		}
	}
	.upload1 {
		width: 100%;
		height: 280rpx;
		position: relative;
		margin: 40rpx auto 10rpx;
		border-radius: 20rpx;
		image {
			width: 100%;
			height: 280rpx;
			border-radius: 20rpx;
		}
		.ads {
			position: absolute;
			image {
				width: 88rpx;
				height: 88rpx;
			}
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #ffffff;
			text-align: center;
		}
		.adsts {
			position: absolute;
			font-size: 28rpx;
			width: 100%;
			height: 80rpx;
			background: rgba(0, 0, 0, 0.5);
			border-radius: 0rpx 0rpx 20rpx 20rpx;
			bottom: 0%;
			line-height: 80rpx;
			color: #ffffff;
			text-align: center;
		}
	}
}
.contents {
	.right_item {
		width: 710rpx;
		background: #ffffff;
		margin: 0rpx auto 20rpx;
		border-radius: 20rpx;
		padding: 20rpx;
		box-sizing: border-box;
		.right_item_block {
			display: flex;
			flex: 1;
			image {
				display: block;
				width: 140rpx;
				height: 190rpx;
				border-radius: 8rpx;
			}
			.right_cont {
				flex: 1;
				margin-left: 12rpx;
				display: flex;
				flex-direction: column;
				box-sizing: border-box;
				justify-content: space-between;
				width: 0;
				.title {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #000000;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.tip {
					margin: 10rpx 0rpx 0rpx 0rpx;
					.t1 {
						padding: 0rpx 6rpx;
						height: 32rpx;
						background: #b19561;
						border-radius: 8rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 20rpx;
						color: #ffffff;
						line-height: 32rpx;
						margin-right: 10rpx;
					}
					.t2 {
						padding: 0rpx 6rpx;
						height: 28rpx;
						border-radius: 8rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 20rpx;
						color: #615b56;
						line-height: 28rpx;
						border: 1px solid #615b56;
						margin-right: 10rpx;
					}
				}
				.user {
					margin-top: 10rpx;
					image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 10rpx;
						border-radius: 12rpx;
					}
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 20rpx;
					color: #8f8f8b;
				}
				.tips {
					margin-top: 6rpx;
					image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 10rpx;
						border-radius: 12rpx;
					}
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 20rpx;
					color: #8f8f8b;
					.ts {
						flex: 1;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
				}
			}
			.zt {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #8f8f8b;
			}
		}
		.tss {
			margin-top: 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 20rpx;
			color: #892b1b;
		}
		.bottom {
			margin-top: 12rpx;
			.text_flex {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #8c8c8c;
				position: relative;
			}
			.btn {
				width: 128rpx;
				height: 40rpx;
				background: #e3d0ad;
				border-radius: 40rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #75613e;
				line-height: 40rpx;
				text-align: center;
				border: 1px solid #e3d0ad;
			}
		}
	}
}
</style>
